package com.mall.service.marketing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.commons.common.CommonPage;
import com.mall.model.domain.SmsHomeAdvertise;
import com.mall.service.marketing.mapper.HomeAdvertiseMapper;
import com.mall.service.marketing.service.HomeAdvertiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import javax.swing.*;
import java.util.List;

/**
 * @ClassName HomeServiceImpl
 * @Description
 * @Author Young
 * @Date 2023/3/12 13:41
 * @Version 1.0
 */
@Service
public class HomeAdvertiseServiceImpl extends ServiceImpl<HomeAdvertiseMapper,SmsHomeAdvertise> implements HomeAdvertiseService {

    @Autowired
    private HomeAdvertiseMapper homeAdvertiseMapper;

    /**
     * 添加广告
     * @param sha
     */
    @Override
    public void create(SmsHomeAdvertise sha) {
        homeAdvertiseMapper.insert(sha);
    }

    /**
     * 删除广告
     * @param ids
     */
    @Override
    public void delete(List<Integer> ids) {
        homeAdvertiseMapper.deleteBatchIds(ids);
    }

    /**
     * 分页查询广告
     * @param endTime
     * @param name
     * @param pageNum
     * @param pageSize
     * @param type
     * @return
     */
    @Override
    public CommonPage myList(String endTime, String name, Integer pageNum, Integer pageSize, Integer type) {
        Page<SmsHomeAdvertise> ipage = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<SmsHomeAdvertise> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(endTime !=null,SmsHomeAdvertise::getEndTime,endTime)
                .eq(type != null,SmsHomeAdvertise::getType,type)
                .like(name != null,SmsHomeAdvertise::getName,name);
        homeAdvertiseMapper.selectPage(ipage,queryWrapper);
        CommonPage page = CommonPage.getPage(ipage);
        return page;
    }

    /**
     * 修改上下线状态
     * @param id
     * @param status
     */
    @Override
    public void updateStatus(Integer id, Integer status) {
        SmsHomeAdvertise smsHomeAdvertise = new SmsHomeAdvertise();
        smsHomeAdvertise.setId(Long.valueOf(id));
        smsHomeAdvertise.setStatus(status);
        homeAdvertiseMapper.updateById(smsHomeAdvertise);
    }

    /**
     * 修改广告
     * @param id
     * @param smsHomeAdvertise
     */
    @Override
    public void myUpdate(Integer id, SmsHomeAdvertise smsHomeAdvertise) {
        homeAdvertiseMapper.updateById(smsHomeAdvertise);
    }

    /**
     * 获取广告详情
     * @param id
     * @return
     */
    @Override
    public SmsHomeAdvertise getInfo(Integer id) {
        SmsHomeAdvertise smsHomeAdvertise = homeAdvertiseMapper.selectById(id);
        return smsHomeAdvertise;
    }

}
